﻿using System.Data.Entity;

namespace BenzInfo.Hockey.Grenadiers.Models
{
    public class GrenadiersContext : DbContext
    {
        public DbSet<Staff> Staff { get; set; }
        public DbSet<Partner> Partners { get; set; }
        public DbSet<Player> Players { get; set; }
        public DbSet<Ad> Ads { get; set; }
        public DbSet<Post> Posts { get; set; }
        public DbSet<Team> Teams { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Game> Games { get; set; }
        public DbSet<Event> Events { get; set; }
        public DbSet<Picture> Pictures { get; set; }
        public DbSet<Background> Backgrounds { get; set; }
        public DbSet<NewsFile> NewsFiles { get; set; }
        public DbSet<HotNews> HotNews { get; set; }
        public DbSet<NewsletterIncsription> NewsletterIncsription { get; set; }
        public DbSet<NewsletterEmail> NewsletterEmail { get; set; }
        public DbSet<Question> Questions { get; set; }
        public DbSet<Answer> Answers { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Post>()
                .HasRequired(m => m.UserCreatedBy)
                .WithMany()
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Post>()
                .HasRequired(m => m.UserModifiedBy)
                .WithMany()
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Event>()
                .HasRequired(m => m.UserCreatedBy)
                .WithMany()
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Event>()
                .HasRequired(m => m.UserModifiedBy)
                .WithMany()
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Game>()
                .HasRequired(m => m.HomeTeam)
                .WithMany()
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<Game>()
                .HasRequired(m => m.AwayTeam)
                .WithMany()
                .WillCascadeOnDelete(false);
        }
    }
}